package com.ysw.rpc.client.config;

import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import com.alibaba.cloud.nacos.NacosServiceManager;
import com.ysw.rpc.client.annotatiaon.process.RpcClientAnnotationBeanPostProcessor;
import com.ysw.rpc.client.component.ChannelComponent;
import com.ysw.rpc.client.component.NacosComponent;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * @author YinShangwen
 * @since 2023/4/10 9:27
 */
public class ClientAutoConfiguration {

    @Bean
    @ConfigurationProperties(prefix = "y-rpc.client")
    public ClientProperties clientProperties() {
        return new ClientProperties();
    }

    @Bean
    public NacosComponent nacosComponent(NacosDiscoveryProperties nacosDiscoveryProperties, NacosServiceManager nacosServiceManager) {
        return new NacosComponent(nacosDiscoveryProperties, nacosServiceManager);
    }

    @Bean
    public ChannelComponent channelComponent(ClientProperties clientProperties, NacosComponent nacosComponent) {
        return new ChannelComponent(clientProperties, nacosComponent);
    }

    @Bean
    public RpcClientAnnotationBeanPostProcessor rpcClientAnnotationBeanPostProcessor() {
        return new RpcClientAnnotationBeanPostProcessor();
    }

    @Bean
    public NacosServiceRegistryBeanPostProcess nacosServiceRegistryBeanPostProcess() {
        return new NacosServiceRegistryBeanPostProcess();
    }

}
